package com.binest.kolInclusion.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.kolInclusion.domain.KolInclusion;
import com.binest.kolInclusion.service.IKolInclusionService;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * KOL收录Controller
 * 
 * @author binest
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/kolInclusion")
public class KolInclusionController extends BaseController
{
    @Autowired
    private IKolInclusionService kolInclusionService;

    /**
     * 查询KOL收录列表
     */
    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:list')")
    @GetMapping("/list")
    public TableDataInfo list(KolInclusion kolInclusion)
    {
        startPage();
        List<KolInclusion> list = kolInclusionService.selectKolInclusionList(kolInclusion);
        return getDataTable(list);
    }

    /**
     * 查询es中KOL收录列表
     */
    @GetMapping("/esList")
    public TableDataInfo esList(KolInclusion kolInclusion) throws Exception {

        TableDataInfo list = kolInclusionService.selectKolInclusionEsList(kolInclusion);
        return list;
    }
    /**
     * 导出KOL收录列表
     */
    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:export')")
    @Log(title = "KOL收录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KolInclusion kolInclusion)
    {
        List<KolInclusion> list = kolInclusionService.selectKolInclusionList(kolInclusion);
        ExcelUtil<KolInclusion> util = new ExcelUtil<KolInclusion>(KolInclusion.class);
        util.exportExcel(response, list, "KOL收录数据");
    }

    /**
     * 获取KOL收录详细信息
     */
    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(kolInclusionService.selectKolInclusionById(id));
    }

    /**
     * 获取es中KOL收录详细信息
     */
    @GetMapping(value = "/getEsInfo")
    public AjaxResult getEsInfo(String id) throws Exception {
        return success(kolInclusionService.selectEsKolInclusionById(id));
    }
    /**
     * 新增KOL收录
     */
//    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:add')")
    @Log(title = "KOL收录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody KolInclusion kolInclusion)
    {
        return success(kolInclusionService.insertKolInclusion(kolInclusion));
    }

    /**
     * 修改KOL收录
     */
    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:edit')")
    @Log(title = "KOL收录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KolInclusion kolInclusion)
    {
        return toAjax(kolInclusionService.updateKolInclusion(kolInclusion));
    }

    /**
     * 删除KOL收录
     */
    @PreAuthorize("@ss.hasPermi('kolInclusion:kolInclusion:remove')")
    @Log(title = "KOL收录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(kolInclusionService.deleteKolInclusionByIds(ids));
    }
}
